class ResTest extends egret.DisplayObjectContainer{

	public constructor() {
		super();
		this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddToStage,this);
	}

	private onAddToStage(evt:egret.Event){
		RES.addEventListener(RES.ResourceEvent.GROUP_COMPLETE,this.onGroupComplete,this);
		RES.getResByUrl("resource/myRoleAni.json",this.onAniLoaded,this,RES.ResourceItem.TYPE_SHEET);
		RES.loadConfig("resource/default.res.json","resource/");
		RES.loadGroup("preload");
	}
	private onAniLoaded(data,url):void
	{
		let sheet:egret.SpriteSheet = data;				
		var tpl:SheetTemplet = new SheetTemplet(sheet);

		
		var ani_1:Animation = new Animation(tpl);
		this.addChild(ani_1);
		ani_1.play('attack');
		
		
		var ani_2:Animation = new Animation(tpl);
		ani_2.interval = 60;
		this.addChild(ani_2);
		ani_2.play('attack');
		ani_2.x = ani_2.y = 100;
		

		
		let w:number = egret.Capabilities.boundingClientWidth;
        let h:number = egret.Capabilities.boundingClientHeight;
        let count:number = 1000;
        for(let i:number=0;i<count;i++){
            var ani:Animation = new Animation(tpl);
			this.addChild(ani);
			ani.play('attack');
			let gap:number = 60;
			ani.x = gap+Math.random()*(w-gap);
			ani.y = gap+Math.random()*(h-gap);
        }
		

	}
	private onGroupComplete(evt:RES.ResourceEvent){
		/*
		let res:any = RES.getRes("myRoleAni_json");
		console.log("资源组加载完成..",res);
		let bitmap:egret.Bitmap = new egret.Bitmap();
		bitmap.x = 100;
		bitmap.y = 100;
		bitmap.texture = RES.getRes("myRoleAni_json.attack0"); // bg_jpg egret_icon_png
		this.addChild(bitmap);
		let gf:egret.GlowFilter = new egret.GlowFilter(0xffff00,1,3,3,2,egret.BitmapFilterQuality.LOW)
		//bitmap.filters = [gf];
		bitmap.texture.saveToFile("image/png","resource/top.png",new egret.Rectangle(0,0,60,60))
		*/
	} 
	public static fnPrint(){
		console.log("fnPrint....")
	}

}